package com.ljj.examisto.data.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.ljj.examisto.databinding.ItemExamBinding
import com.ljj.examisto.data.item.ExamItem

class ExamAdapter(
    private val exams: List<ExamItem>,
    private val onItemClick: (String) -> Unit
) : RecyclerView.Adapter<ExamAdapter.ExamViewHolder>() {

    inner class ExamViewHolder(private val binding: ItemExamBinding) : RecyclerView.ViewHolder(binding.root) {
        fun bind(examItem: ExamItem) {
            binding.tvExamName.text = examItem.examName
            binding.tvStartTime.text = examItem.startTime
            binding.llExamItem.setOnClickListener {
                onItemClick(examItem.examName)
            }
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExamViewHolder {
        val binding = ItemExamBinding.inflate(
            LayoutInflater.from(parent.context),
            parent,
            false
        )
        return ExamViewHolder(binding)
    }

    override fun onBindViewHolder(holder: ExamViewHolder, position: Int) {
        holder.bind(exams[position])
    }

    override fun getItemCount(): Int = exams.size
}